package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.Product;
import com.spzx.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/product")
public class ProductController extends BaseController {
    @Autowired
    private ProductService productService;

    @GetMapping("/list")
    public TableDataInfo getProductListPage() {
        startPage();
        List<Product> list = productService.getProductListPage();
        return getDataTable(list);
    }

    @PostMapping
    public AjaxResult saveProduct(@RequestBody Product product) {
        productService.saveProduct(product);
        return AjaxResult.success();
    }

    @GetMapping("/updateStatus/{id}/{status}")
    public AjaxResult updateStatus(
            @PathVariable Long id,
            @PathVariable Integer status) {
        productService.updateStatus(id, status);
        return AjaxResult.success();
    }
    @DeleteMapping("/{ids}")
    public AjaxResult deleteProduct(@PathVariable List<Long> ids){
        productService.deleteProductById(ids);
        return AjaxResult.success();
    }
}
































